//实现ADC的接口的样品Demo
//主要提供 使用TempADC的Demo
//负责跟外部沟通

#include "../App_Main.h"

_Temp_Param Temp_Param;
extern bool F_C_flag;

uint32_t adc_model_convert_voltage(uint32_t ad)
{
    float temp;
    uint32_t voltage;

    temp = ad;
    temp /= 4095.0;
    temp *= 4950.0; //5000mV,假设误差1%,实际电压趋近5000mV; 经过万用表测量1%误差的计算结果很接近实际电压值
    temp *= 0.66; //将5v供电转换3.3v供电的温度分压电路,以便拟合运算
    voltage = temp;

    return voltage;
}

void adc_model_delay0ms_output(void)
{
    if(RTD[0].status == Pt_Normal)
    {
        // Temp_Param.oven = RTD[0].value;

		Temp_Param.probe1 = RTD[1].value;
		Temp_Param.probe2 = RTD[2].value;
        
    }
    else if(RTD[0].status == Pt_Open)
    {
        if(Temp_Param.oven_Err == Pt_Normal) Temp_Param.oven_Err = Pt_Open; //确保只能出现一种Er报警错误显示
    }
    else if(RTD[0].status == Pt_Short)
    {
        if(Temp_Param.oven_Err == Pt_Normal) Temp_Param.oven_Err = Pt_Short;
    }
    else if(RTD[0].status == Pt_LowTemp)
    {
        if(Temp_Param.oven_Err == Pt_Normal) Temp_Param.oven_Err = Pt_LowTemp;
    }
    else if(RTD[0].status == Pt_HighTemp)
    {
        if(Temp_Param.oven_Err == Pt_Normal) Temp_Param.oven_Err = Pt_HighTemp;
    }

    if (RTD[1].status == Pt_Normal) Temp_Param.probe1_Err = Pt_Normal;
    else if(RTD[1].status == Pt_Short) Temp_Param.probe1_Err = Pt_Short;
    else if(RTD[1].status == Pt_Open) Temp_Param.probe1_Err = Pt_Open;

    if (RTD[2].status == Pt_Normal) Temp_Param.probe2_Err = Pt_Normal;
    else if(RTD[2].status == Pt_Short) Temp_Param.probe2_Err = Pt_Short;
    else if(RTD[2].status == Pt_Open) Temp_Param.probe2_Err = Pt_Open;
}

void adc_model_init(void)
{
    Temp_Param.oven_Err = Pt_Normal;

    ADC_Convert_R = AD_Convert_R; //adc_model_convert_voltage;
    TempADC_Delay0ms_Output = adc_model_delay0ms_output;
}
